package com.freemalll.auth.cloud.business.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.freemalll.auth.cloud.business.domain.dto.SysApplicationDto;
import com.freemalll.auth.cloud.business.domain.dto.validation.AddGroup;
import com.freemalll.auth.cloud.business.domain.dto.validation.UpdateGroup;
import com.freemalll.auth.cloud.business.domain.vo.SysApplicationVo;
import com.freemalll.auth.cloud.business.service.ISysApplicationService;
import com.freemalll.common.core.annotation.ResultInterceptor;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/application")
@Tag(name = "应用管理", description = "应用管理")
@RequiredArgsConstructor
@ResultInterceptor
public class SysApplicationController {

    private final ISysApplicationService applicationService;


    @PostMapping("/page")
    @Operation(summary = "系统应用分页", description = "系统应用分页")
    public Page<SysApplicationVo> queryPage(@RequestBody SysApplicationDto dto) {
        return applicationService.queryPage(dto);
    }

    @PostMapping("/list")
    @Operation(summary = "系统应用列表", description = "系统应用列表")
    public List<SysApplicationVo> queryList(@RequestBody SysApplicationDto dto) {
        return applicationService.queryList(dto);
    }

    @DeleteMapping(value = "/{appId}")
    @Operation(summary = "根据ID删除系统应用", description = "根据ID删除系统应用")
    public void deleteApplication(@PathVariable(value = "appId") String appId) {
        applicationService.deleteApplication(appId);
    }

    @PostMapping("/add")
    @Operation(summary = "新增系统应用", description = "新增系统应用")
    public void add(@Validated(AddGroup.class) @RequestBody SysApplicationDto dto) {
        applicationService.insertApplication(dto);
    }

    @PostMapping("/update")
    @Operation(summary = "修改系统应用", description = "修改系统应用")
    public void edit(@Validated(UpdateGroup.class) @RequestBody SysApplicationDto dto) {
        applicationService.updateApplication(dto);
    }


}
